/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package LN;

import Objects.GroupSupplier;
import Objects.Supplier;
import Tools.Datos;
import Tools.Tools;
import Tools.Validar;
import WSClient.WSClientProveedor;
import Wsdl.RespBdProveedor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 *
 * @author ARMGARCES
 */
public class LnProveedor {    
    /***************************************************************************/
    /******************************** SUPPLIER *********************************/
    /***************************************************************************/
    /**
     * 
     * @lista para generar el reporte
     * @param supplier
     * @return 
     */
    public static List<Supplier> getList_Supplier(Supplier[] supplier){
        List<Supplier> list = new ArrayList<>();        
        list.addAll(Arrays.asList(supplier));        
        return list;
    }   
    /**
     * 
     * @return 
     */
    public Supplier[] load_Supplier() {
//        try{
        RespBdProveedor resp = WSClient.WSClientProveedor.loadSupplier();
        if(resp.getEsNulo() == 0){
            List<Wsdl.Supplier> suppliers = resp.getSuppliers();            
            return (Supplier[]) suppliers.toArray();             
        }else{
            Tools.checkRespNull(resp.getError());
        }
//        }catch(SQLException e){
//            Gui.getInstance().ventanaError("Error Cargando Proveedor: \n"+e.getMessage()); 
//        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     */
    public Supplier[] find_Supplier(String find) {
//        try{
        RespBdProveedor resp = WSClientProveedor.findSupplier(find);
        if(resp.getEsNulo() == 0){
            List<Wsdl.Supplier> suppliers = resp.getSuppliers();            
            return (Supplier[]) suppliers.toArray();             
        }else{
            Tools.checkRespNull(resp.getError());
        }
//        }catch(SQLException e){
//            Gui.getInstance().ventanaError("Error Cargando Proveedor: \n"+e.getMessage()); 
//        }
        return null;
    }    
    /**
     * @author MITM
     * @param supplier
     * @param operacion
     * @return 
     */
    public boolean save_Supplier(Supplier supplier, int operacion) {
        boolean boo = Validar.validar_SaveSupplier(supplier);
        if (boo){
//            try{
                RespBdProveedor resp = WSClientProveedor.saveSupplier(Datos.getSesion().getUsername(),supplier.getWsdlValue(),operacion);
                if(resp.getEsNulo() == 0){
                    if(resp.getResult() == 1) return true; 
                }else{
                    Tools.checkRespNull(resp.getError());
                }
//            }catch(Exception e){
//                Gui.getInstance().ventanaError("Error guardando Proveedor: \n"+e.getMessage()); 
//            }
        }        
        return false;
    }
    /**
     *
     * @param supplierRif
     * @return 
     */
    public boolean check_Supplier(String supplierRif) {
        RespBdProveedor resp = WSClientProveedor.checkSupplier(supplierRif);
        if(resp.getEsNulo() == 0){
            Datos.setStSeniat(resp.getSeniat());
            if(resp.getResult() == 1) return true;             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return false;
    }
    /**
     * @author MITM
     * @param supplier
     * @return 
     */
    public boolean change_Supplier(Supplier supplier) {
//        try{
//            return Bd.getInstance().change_Supplier(supplier);                
//        }catch(Exception e){       
////            Gui.getInstance().ventanaError("Error Deshabilitando Proveedor: \n"+e.getMessage()); 
//        }
//        return false;
        RespBdProveedor resp = WSClientProveedor.changeSupplier(Datos.getSesion().getUsername(), supplier.getWsdlValue());
        if(resp.getEsNulo() == 0){
            if(resp.getResult() == 1) return true;             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return false;
    }        
    /***************************************************************************/
    /***************************** GROUPSUPPLIER *******************************/
    /***************************************************************************/    
    /**
     * @author MITM
     * @lista para generar el reporte
     * @param groupsupplier
     * @return 
     */
    public static List<GroupSupplier> getList_GroupSupplier(GroupSupplier[] groupsupplier){
        List<GroupSupplier> list = new ArrayList<>();        
        list.addAll(Arrays.asList(groupsupplier));        
        return list;
    }
    /**
     * @author MITM
     * @return 
     */
    public GroupSupplier[] load_GroupSupplier() {
//        try{
//            GroupSupplier[] groupsupplier = Bd.getInstance().load_GroupSupplier();      
//            return groupsupplier;
//        }catch(SQLException e){
////            Gui.getInstance().ventanaError("Error Cargando Grupo de Proveedor: \n"+e.getMessage()); 
//        }
//        return null;
        RespBdProveedor resp = WSClient.WSClientProveedor.loadGroupSupplier();
        if(resp.getEsNulo() == 0){
            List<Wsdl.GroupSupplier> groupSuppliers = resp.getGroupSuppliers();
            return  (GroupSupplier[]) groupSuppliers.toArray();             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return null;
    }    
    /**
     * @author MITM
     * @param find
     * @return 
     */
    public GroupSupplier[] find_GroupSupplier(String find) {
//        try{
//            GroupSupplier[] groupsupplier = Bd.getInstance().find_GroupSupplier(find);      
//            return groupsupplier;
//        }catch(SQLException e){
////            Gui.getInstance().ventanaError("Error Cargando Grupo de Proveedor: \n"+e.getMessage()); 
//        }
        RespBdProveedor resp = WSClientProveedor.findGroupSupplier(find);
        if(resp.getEsNulo() == 0){
            List<Wsdl.GroupSupplier> groupSuppliers = resp.getGroupSuppliers();
            return  (GroupSupplier[]) groupSuppliers.toArray();             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return null;
    }    
    /**
     * @author MITM
     * @param groupsupplier
     * @param operacion
     * @return 
     */
    public boolean save_GroupSupplier(GroupSupplier groupsupplier, int operacion) {
        boolean boo = Validar.validar_Save_GroupSupplier(groupsupplier);
        if (boo){
//            try{                
//                boolean result = Bd.getInstance().save_GroupSupplier(operacion, groupsupplier);
//
//                return result;
//            }catch(Exception e){
////                Gui.getInstance().ventanaError("Error guardando Grupo de Proveedor: \n"+e.getMessage()); 
//            }
            RespBdProveedor resp = WSClientProveedor.saveGroupSupplier(Datos.getSesion().getUsername(),groupsupplier.getWsdlValue(),operacion);
            if(resp.getEsNulo() == 0){
                if(resp.getResult() == 1) return true; 
            }else{
                Tools.checkRespNull(resp.getError());
            }
        }        
        return false;
    }
    /**
     * @author MITM
     * @param groupsuppliername
     * @return 
     */
    public boolean check_GroupSupplier(String groupsuppliername) {
//        try{
//            return Bd.getInstance().check_GroupSupplier(groupsuppliername);                
//        }catch(SQLException e){             
//        }
//        return false;
        RespBdProveedor resp = WSClientProveedor.checkGroupSupplier(groupsuppliername);
        if(resp.getEsNulo() == 0){            
            if(resp.getResult() == 1) return true;             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return false;
    }
    /**
     * @author MITM
     * @param groupsupplier
     * @return 
     */
    public boolean change_GroupSupplier(GroupSupplier groupsupplier) {
//        try{
//            return Bd.getInstance().change_GroupSupplier(groupsupplier);                
//        }catch(Exception e){       
////            Gui.getInstance().ventanaError("Error Deshabilitando Grupo de Proveedor: \n"+e.getMessage()); 
//        }
        RespBdProveedor resp = WSClientProveedor.changeGroupSupplier(Datos.getSesion().getUsername(), groupsupplier.getWsdlValue());
        if(resp.getEsNulo() == 0){
            if(resp.getResult() == 1) return true;             
        }else{
            Tools.checkRespNull(resp.getError());
        }
        return false;
    }        
}
